<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="java.sql.*" %>
<%@ page import="com.data.ConnData" %>
<%
    request.setCharacterEncoding("utf-8");
    String questionId = request.getParameter("question_id");
    String questionName = request.getParameter("question_name");
    String questionContent = request.getParameter("question_content");
    String sampleInput = request.getParameter("sample_input");
    String sampleOutput = request.getParameter("sample_output");
    String testCaseInput = request.getParameter("test_case_input");
    String testCaseOutput = request.getParameter("test_case_output");

    ConnData objdata = new ConnData();
    Connection connection = null;
    PreparedStatement psmt = null;
    try {
        connection = objdata.getConn();
        String sql = "UPDATE question_table SET question_name =?, question_content =?, sample_input =?, sample_output =?, test_case_input =?, test_case_output =? WHERE question_id =?";
        psmt = objdata.getPsmt(sql);
        psmt.setString(1, questionName);
        psmt.setString(2, questionContent);
        psmt.setString(3, sampleInput);
        psmt.setString(4, sampleOutput);
        psmt.setString(5, testCaseInput);
        psmt.setString(6, testCaseOutput);
        psmt.setString(7, questionId);
        int rowsAffected = psmt.executeUpdate();
        if (rowsAffected > 0) {
            response.sendRedirect("admin.jsp");
} else {
%>
<p>题目信息修改失败，请稍后再试。</p>
<%
    }
} catch (SQLException e) {
    e.printStackTrace();
%>
<p>数据库操作出现错误，请稍后再试！</p>
<%
    } finally {
        if (psmt!= null) {
            try {
                psmt.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        if (connection!= null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
%>